package com.jsnkj.basic.activity

import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.jsnkj.basic.R
import com.jsnkj.basic.adapter.CashRecordAdapter
import com.jsnkj.basic.bean.IncomeExpenditureEntity
import com.jsnkj.basic.databinding.ActivityCashRecordBinding
import com.jsnkj.basic.mvvm.BaseKtActivity
import com.jsnkj.basic.util.ErrorResultUtil


/**
 *  我的钱包的提现记录
 */
class CashRecordActivity : BaseKtActivity<ActivityCashRecordBinding, CashRecordViewModel>() {
    override val layoutId: Int
        get() = R.layout.activity_cash_record


    var cashAdapter: CashRecordAdapter? = null

    override fun initView(savedInstanceState: Bundle?) {

        mVDB.topTitle.txtTopTitle.text = "提现记录"
        mVDB.topTitle.imageReturn.setOnClickListener {
            onBackPressed()
        }
        mVDB.topTitle.layoutTopTitle.setBackgroundColor(Color.parseColor("#FFFFFF"))


        mVM.errorResult.observe(this) {
            ErrorResultUtil.errorResult(this@CashRecordActivity,it)


            mVDB.rvOutcome.visibility = View.GONE
            mVDB.linTotal.visibility = View.GONE
            mVDB.tvError.visibility = View.VISIBLE
        }

        mVM.postHttpResult.observe(this) {

            mVDB.tvTootal.text = "${it.total}元"
            initRecyclerView(it.list)
        }

        mVM.postWalletOutcomes()
    }


    private fun initRecyclerView(list: List<IncomeExpenditureEntity>?) {

        if (list.isNullOrEmpty()) {
            return
        }

        if (null == cashAdapter) {
            cashAdapter = CashRecordAdapter(this@CashRecordActivity, list)
        }


        mVDB.rvOutcome.apply {
            layoutManager =
                LinearLayoutManager(this@CashRecordActivity, LinearLayoutManager.VERTICAL, false)
            adapter = cashAdapter
        }

        mVDB.rvOutcome.visibility = View.VISIBLE
        mVDB.linTotal.visibility = View.VISIBLE
        mVDB.tvError.visibility = View.GONE
    }


}